﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI.HtmlControls;
using viBlog.Classes;
using viBlog.Controllers;
using visinia.SmartEngine;
using visinia.SmartEngine.Modules;

public partial class Modules_viBlog_Tags_TagCloud : WebModule
{
    private const string LINK = "<a href=\"{0}\" class=\"{1}\" title=\"{2}\">{3}</a> ";

    protected void Page_Load(object sender, EventArgs e)
    {
        WebPageController.AddCssLink(Page, ResolveUrl("TagClouds.css"), true);

        //*****************************************************************************************/
        // Post URL = Blog/Tag/Tag name.aspx
        /*****************************************************************************************/
        List<DataCount> clouds = TagController.GetTagCount();
        foreach (DataCount cloud in clouds)
        {
            Tag tag = TagController.GetTag(cloud.DataId);
            HtmlGenericControl li = new HtmlGenericControl("li");
            
            if (cloud.Count >= 60)
                li.InnerHtml = string.Format(LINK, WebRoots.GetWebRoot + BlogController.BlogUrlSeparator + "/Tag/" + HttpUtility.UrlEncode(tag.Name) + ".aspx", "biggest", tag.Name, tag.Name);
            else if (cloud.Count >= 50)
                li.InnerHtml = string.Format(LINK, WebRoots.GetWebRoot + BlogController.BlogUrlSeparator + "/Tag/" + HttpUtility.UrlEncode(tag.Name) + ".aspx", "big", tag.Name, tag.Name);
            else if (cloud.Count >= 25)
                li.InnerHtml = string.Format(LINK, WebRoots.GetWebRoot + BlogController.BlogUrlSeparator + "/Tag/" + HttpUtility.UrlEncode(tag.Name) + ".aspx", "medium", tag.Name, tag.Name);
            else if (cloud.Count >= 10)
                li.InnerHtml = string.Format(LINK, WebRoots.GetWebRoot + BlogController.BlogUrlSeparator + "/Tag/" + HttpUtility.UrlEncode(tag.Name) + ".aspx", "small", tag.Name, tag.Name);
            else if (cloud.Count >= 0)
                li.InnerHtml = string.Format(LINK, WebRoots.GetWebRoot + BlogController.BlogUrlSeparator + "/Tag/" + HttpUtility.UrlEncode(tag.Name) + ".aspx", "smallest", tag.Name, tag.Name);
            TAGS.Controls.Add(li);
        }
    }
}
